package com.pengheng.example2;

import org.bouncycastle.asn1.*;

import java.io.IOException;

public class Address extends ASN1Object implements ASN1Encodable {
    private DERPrintableString street;
    private DERPrintableString city;

    public Address() {
        super();
    }

    public Address(DERPrintableString street, DERPrintableString city) {
        super();
        this.street = street;
        this.city = city;
    }

    public DERPrintableString getStreet() {
        return street;
    }

    public void setStreet(DERPrintableString street) {
        this.street = street;
    }

    public DERPrintableString getCity() {
        return city;
    }

    public void setCity(DERPrintableString city) {
        this.city = city;
    }

    @Override
    public ASN1Primitive toASN1Primitive() {
        return new DERSequence(new ASN1Encodable[]{street, city});
    }

    public static Address getInstance(Object obj) throws IOException {
        if (obj instanceof Address) {
            return (Address) obj;
        } else if (obj != null) {
            return new Address(DERPrintableString.getInstance(((DERSequence) obj).getObjectAt(0)),
                    DERPrintableString.getInstance(((DERSequence) obj).getObjectAt(1)));
        }
        throw new IllegalArgumentException("Invalid Address: " + obj.getClass().getName());
    }
}